package com.wiki.gds.member.provider.security.oauth2.config;

import com.wiki.gds.base.common.dto.ResponseDto;
import com.wiki.gds.base.common.exception.BizExceptionEnum;
import com.wiki.gds.base.common.utils.ResponseDtoFactory;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;

//@ControllerAdvice
public class OauthResponseBodyAdvice implements ResponseBodyAdvice {


    @Override
    public boolean supports(MethodParameter methodParameter, Class aClass) {
        return methodParameter.getParameterType().isAssignableFrom(ResponseEntity.class)
                &&!methodParameter.getParameterType().isAssignableFrom(ResponseDto.class)
                ;
    }


    @Override
    public Object beforeBodyWrite(Object o, MethodParameter methodParameter, MediaType mediaType, Class aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
        ResponseDto rs= ResponseDtoFactory.GetInstance().build(BizExceptionEnum.SUCCESSFUL_OPERATION);
        rs.setData(o);
        return rs;
    }
}